import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author: gao
 * @create-date: 2025/3/15 20:21
 */

public class Solution {
    public int numJewelsInStones(String jewels, String stones){
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < jewels.length(); i++) {
            char ch = jewels.charAt(i);
            set.add(ch);
        }
        int count = 0;
        for (int i = 0; i < stones.length(); i++) {
            char ch = stones.charAt(i);
            if(set.contains(ch)){
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String jewels = in.nextLine();
            String stones = in.nextLine();
            Solution solution = new Solution();
            System.out.println(solution.numJewelsInStones(jewels, stones));
        }
    }
}
